package com.ruoyi.patrol.controller;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.patrol.domain.PtLineRecordDetail;
import com.ruoyi.patrol.domain.vo.PtSiteRecordVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtSiteRecordStaff;
import com.ruoyi.patrol.service.IPtSiteRecordStaffService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 点位巡逻记录(行政)Controller
 * 
 * @author mlb
 * @date 2022-11-23
 */
@RestController
@RequestMapping("/patrol/site_record_staff")
public class PtSiteRecordStaffController extends BaseController
{
    @Autowired
    private IPtSiteRecordStaffService ptSiteRecordStaffService;

    /**
     * 查询点位巡逻记录(行政)列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:site_record_staff:list')")
    @GetMapping("/list")
    public AjaxResult list(PtSiteRecordStaff ptSiteRecordStaff)
    {
        List<PtSiteRecordStaff> list = ptSiteRecordStaffService.selectPtSiteRecordStaffList(ptSiteRecordStaff);
        return AjaxResult.success(list);
    }

    /**
     * 导出点位巡逻记录(行政)列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:site_record_staff:export')")
    @Log(title = "点位巡逻记录(行政)", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PtSiteRecordStaff ptSiteRecordStaff)
    {
        List<PtSiteRecordStaff> list = ptSiteRecordStaffService.selectPtSiteRecordStaffList(ptSiteRecordStaff);
        ExcelUtil<PtSiteRecordStaff> util = new ExcelUtil<PtSiteRecordStaff>(PtSiteRecordStaff.class);
        return util.exportExcel(list, "site_record_staff");
    }

    /**
     * 获取点位巡逻记录(行政)详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:site_record_staff:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ptSiteRecordStaffService.selectPtSiteRecordStaffById(id));
    }

    /**
     * 新增点位巡逻记录(行政)
     */
    @PreAuthorize("@ss.hasPermi('patrol:site_record_staff:add')")
    @Log(title = "点位巡逻记录(行政)", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtSiteRecordStaff ptSiteRecordStaff)
    {
        return toAjax(ptSiteRecordStaffService.insertPtSiteRecordStaff(ptSiteRecordStaff));
    }

    @PreAuthorize("@ss.hasPermi('patrol:site_record_staff:edit')")
    @Log(title = "点位巡逻记录(行政)", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtSiteRecordStaff ptSiteRecordStaff)
    {
        PtSiteRecordVo ptLineRecordVo = new PtSiteRecordVo();
        ptLineRecordVo.setRecordId(ptSiteRecordStaff.getId());
        ptLineRecordVo.setState(ptSiteRecordStaff.getState());
        ptLineRecordVo.setHandleInfo(StringUtils.isEmpty(ptSiteRecordStaff.getHandleInfo()) ? null : ptSiteRecordStaff.getHandleInfo());

        return toAjax(ptSiteRecordStaffService.handleAbnormal(ptLineRecordVo));
    }
}
